package com.me.test.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.jackson.JacksonProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.Locale;

/**
 * 依赖注入的 静态单例bean
 */
@Component
public class SingletonBeanUtil {
    private static SingletonBeanUtil instance;

    @Autowired
    private JacksonProperties jacksonProperties;

    private static String env;
    private static Locale locale;
    private static String dateFormat;

    @Value("${spring.profiles.active}")
    public void setEnv(String env) {
        SingletonBeanUtil.env = env;
    }

    @Autowired
    public void setUcClient(JacksonProperties properties) {
        SingletonBeanUtil.locale = properties.getLocale();
        SingletonBeanUtil.dateFormat = properties.getDateFormat();
    }


    @PostConstruct
    public void init() {
        SingletonBeanUtil.instance = this;
    }

    public static SingletonBeanUtil getInstance(){
        return instance;
    }

}
